package com.sad.dao.impl;

import java.io.IOException;
import java.util.Map;

import org.codehaus.jackson.JsonParseException;
import org.codehaus.jackson.map.JsonMappingException;
import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.type.TypeReference;

import com.sad.dao.BaseRecord;
import com.sad.model.JsonObject;
import com.sad.model.Reshelf;
import com.sad.util.G;

/**
 * 
 * @author zhaoqy
 *
 */
public class ReshelfRecord extends BaseRecord<Reshelf> {

	@Override
	protected String getUrl(Map<String, Object> parms) {
		String url = "";
		String action = (String) parms.get("action");

		if ("create".equals(action)) {
			String backid = (String) parms.get("backid");

			url = G.system.url + "/toy/orderback/shelves?backid=" + backid;
		} else if ("table".equals(action)) {
			String page = (String) parms.get(G.K.page);
			String pageSize = (String) parms.get(G.K.perPage);
			url = G.system.url + "/toy/orderback/backlist?pageNo=" + page + "&pageSize=" + pageSize;

			String condation = (String) parms.get("condation");
			if (condation != null && !"".equals(condation)) {
				url += "&toycode=" + condation;
			}
		}

		return url;
	}

	@Override
	protected JsonObject<Reshelf> parserJsonObject(String json) throws JsonParseException,
			JsonMappingException, IOException {
		ObjectMapper mapper = new ObjectMapper();
		return mapper.readValue(json, new TypeReference<JsonObject<Reshelf>>() {
		});
	}
}
